package com.home.homepage.controller.banner;

import com.eig.common.entity.homepageentity.banner.CrmBanner;
import com.eig.common.vo.Result;
import com.home.homepage.service.banner.BannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author ：YQ袁（2446806940@qq.com）
 * @date ：Created in 2022/12/16 17:25
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/home/banner/")
@Api(tags = "轮播管理接口")
public class BannerController {


    @Autowired
    private BannerService bannerService;

    @PostMapping("/getAllBanner/{current}/{pageSize}")
    @ApiOperation(value = "分页查询",notes = "根据current，pageSize 查询")
    public Result getAllBanner(@PathVariable(required = true) Integer current,
                               @PathVariable(required = true) Integer pageSize,
                               @RequestBody CrmBanner crmBanner
                               ){
        return bannerService.getAllBanner(current,pageSize,crmBanner);
    }

    @PostMapping("/uploadMsg")
    @ApiOperation(value = "上传图片")
    public String uploadMsg(MultipartFile file){
        String url = bannerService.uploadFileAvatar(file);
        System.out.println(url);
        return bannerService.uploadFileAvatar(file);
    }
    @PostMapping("/addBanner")
    @ApiOperation(value = "添加接口")
    public Result addBanner( @RequestBody CrmBanner crmBanner ){
        return  bannerService.addBanner(crmBanner);
    }

    @PostMapping("/updateBanner")
    @ApiOperation(value = "修改接口",notes = "实体类")
    public Result updateBanner( @RequestBody CrmBanner crmBanner ){
        return  bannerService.updateBanner(crmBanner);
    }

    @PostMapping("/changeStatus/{id}/{isDisable}")
    @ApiOperation(value = "修改状态接口" ,notes = "根据 id 修改 isDisable")
    public Result changeStatus( @PathVariable String id,
                                @PathVariable String isDisable
    ){
        return  bannerService.changeStatus(id,isDisable);
    }
    @PostMapping("/deleteBanner")
    @ApiOperation(value = "删除接口")
    public Result deleteBanner(@RequestBody CrmBanner crmBanner){
        return bannerService.deleteBanner(crmBanner);
    }
}
